package com.javalong.affairs.module.renwujinzhang.activity.praise.fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;

import com.javalong.affairs.R;
import com.javalong.affairs.base.data.AllData;
import com.javalong.affairs.base.fragment.BaseFragment;
import com.javalong.affairs.base.ui.SimplePullRefreshList;
import com.javalong.affairs.base.utils.ListUtils;
import com.javalong.affairs.module.renwujinzhang.adapter.TrackTaskAdapter;
import com.javalong.affairs.module.renwujinzhang.model.Task;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * Created by 杨观回 on 2016/2/28 0028.
 */
public abstract class PraiseListFragment extends BaseFragment implements
        AdapterView.OnItemClickListener {


    private SimplePullRefreshList lv_task;
    private TrackTaskAdapter ad_task;
    private List<Task> taskList;


    public Task getTask(int index) {
        return ListUtils.getSafeItem(taskList, index);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_task,
                container, false);
        lv_task = (SimplePullRefreshList) view
                .findViewById(R.id.lv_task);

        taskList = AllData.GetInstance().appendListData(
                getDataId(),
                new ArrayList<Task>());

        ad_task = new TrackTaskAdapter(getActivity(), taskList);
        lv_task.setAdapter(ad_task);
        lv_task.initData(getMapData());
        lv_task.refresh();
        lv_task.setOnItemClickListener(this);
        afterInit();
        return view;
    }

    protected abstract void afterInit();

    protected abstract int getDataId();

    protected abstract Map<String, Object> getMapData();

    @Override
    public void refresh() {
        super.refresh();
        lv_task.refresh();
    }
}
